package cn.learn.activiti.controller;

import cn.learn.activiti.domain.ActNodeConfig;
import cn.learn.activiti.service.IProcessService;
import cn.learn.activiti.util.RestResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * @author huangyezhan
 * @version 1.0
 * @date 2021年03月12日22:27
 */

@Slf4j
@RequiredArgsConstructor
@RequestMapping(path = "/activity/process")
@RestController
public class ProcessController {
    private final IProcessService processService;

    /**
     * 启动流程
     */
    @PutMapping
    public RestResponse startProcess(@RequestParam String processKey, @RequestParam String businessKey) {
        Map<String, Object> variables    = new HashMap<>(8);
        Set<String>         assigneeList = new HashSet<>();
    /*    assigneeList.add("jerry");
        assigneeList.add("tom");
        variables.put("assigneeList", assigneeList);
        variables.put("num", 2);*/
//
        //variables.put("termId", "activitiTeam,otherTeam");
     /*   variables.put("candidateUsers_Activity_1xksixc", "jack");
        variables.put("candidateGroups_Activity_1xksixc", "activitiTeam");
        variables.put("dueDate_Activity_1xksixc", new Date());*/

        variables.put("account", "null");
        variables.put("group", "activitiTeam,ACTIVITI_ADMIN");
//        variables.put("dueDate_Activity_1xksixc", new Date());

        ActNodeConfig config = new ActNodeConfig().setAutomateTask(true)
                .setMessage("测试用例")
                .setReceiver("测试人");
        processService.startProcess(processKey, businessKey, null, config);
        return RestResponse.success();
    }

    /**
     * 删除流程
     * 要删除 act_ru_execution的id，还是流程的id才行
     */
    @DeleteMapping("/{executionId}")
    public RestResponse deleteProcessInstances(@PathVariable String executionId) {
        String reason = "删除_定义流程，拜拜咯！";
        processService.deleteProcessInstances(executionId, reason);
        return RestResponse.success();
    }


}
